package com.ks.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ks.entity.Questiontype;
import com.ks.service.QuestiontypeService;

@Controller
@RequestMapping("/questionType")
public class QuestiontypeController {

    @Autowired
    private QuestiontypeService<Questiontype> questiontypeService;

    /**
     * 跳转到试题类型管理页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("toQuestiontype")
    public String toQuestiontype(Model model, HttpServletRequest request, HttpServletResponse response) {
        questiontypeService.toQuestiontype(model);
        return "pages/typManagement/item-type-add-2";
    }

    /**
     * 保存修改
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("save")
    @ResponseBody
    public Map<String, Object> save(HttpServletRequest request, HttpServletResponse response) {
        String typeList = request.getParameter("typeList");

        return questiontypeService.save(typeList);
    }

    /**
     * 删除试题类型
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("deltype")
    @ResponseBody
    public Map<String, Object> deltype(HttpServletRequest request, HttpServletResponse response) {
        String delId = request.getParameter("delId");
        return questiontypeService.deltype(delId);
    }
}
